package demo.practice.competition;

public class P1894 {


    public int chalkReplacer(int[] chalk, int k) {

        int sum = 0;
        for (int i : chalk) {
            if (sum > k)   // 加法运算一定得记得 32位溢出问题
                break;
            sum += i;
        }

        k = k % sum;
        if (k == 0)    //整除
            return 0;


        for (int i = 0; i < chalk.length; i++) {

            if (k < chalk[i])
                return i;

            k = k - chalk[i];
        }

        return -1;
    }
}
